#ifndef _CONNECTION_H_
#define _CONNECTION_H_

#include <string>
#include <windows.h>
#include "defs.h"

#pragma comment (lib, "ws2_32.lib")
#pragma comment (lib, "mswsock.lib")

/************************************************************************
 Class to set connection between client and server.
 TODO: encryption ( open key )
/************************************************************************/


class Connection
{

#pragma region CLIENT

#ifdef _CLIENT_PART_

private:

    char* m_ClientName_Client;                                              // client computer name
    char* m_ServerName_Client;                                              // server computer name             
    std::string m_ServerIP_Client;                                          // IP-addres
    WSAData m_ClientWSADat_Client;                                          // winsock option
    sockaddr_in m_ClientSocketInfo_Client;                                  // client socket option
    SOCKET m_ClientSocket_Client;                                           // client socket

public:
    explicit Connection();

    Connection( const Connection& );                                        // lock
    Connection& operator= ( const Connection& );                            // lock
    ~Connection();

    bool StartConnection();
    bool ConnectToServer();
    bool DisconnectFromServer();
    
    bool PingServer();
    bool CheckConnection(){return true;}

    void GetSocket() const;
    bool SetIP( std::string& ip );                                          // set server IP

#endif //_CLIENT_PART_

#pragma endregion



#pragma region SERVER

#ifdef _SERVER_PART_
private:
    char* m_ClientName_Serv;                                                // client computer name
    char* m_ServerName_Serv;                                                // server computer name             
    WSAData m_ServerWSADat_Serv;                                            // winsock option
    sockaddr_in m_ServerSocketInfo_Serv;                                    // server socket info
    SOCKET m_ServerSocket_Serv, m_ClientSocket_Serv;                        // server and client sockets

public:
    explicit Connection();

    Connection( const Connection& );                                        // lock
    Connection& operator= ( const Connection& );                            // lock
    ~Connection();

    bool StartConnection();
    bool ConnectToClient();
    bool DisconnectFromClient();

    bool CheckConnection(){return true;}

#endif

#pragma endregion




};


#endif